package cn.ilikes.tools.hbase.jpa.persistences.context.operations;

import cn.ilikes.tools.hbase.jpa.clients.AbClient;
import cn.ilikes.tools.hbase.jpa.persistences.context.AbstractContext;
import cn.ilikes.tools.hbase.jpa.persistences.context.Operation;
import cn.ilikes.tools.hbase.jpa.query.iquerys.JPAQuery;

public class QueryOperation extends ContextOperation implements Operation<Object> {

	public static enum QueryType {
		List, Single

	}

	public JPAQuery getJpaQuery() {
		return jpaQuery;
	}

	private JPAQuery jpaQuery;

	public QueryOperation(OperationType operationType, AbstractContext context, JPAQuery jpaQuery) {
		super(operationType, context);
		this.jpaQuery = jpaQuery;
	}

	@Override
	public boolean initSub(AbstractContext context) {
		jpaQuery.init();
		return true;
	}

	@Override
	public Object exec() {
		AbClient client = getContext().getClient();
		jpaQuery.setClient(client);
		jpaQuery.setContext(getContext());
		return jpaQuery.queryResult();

	}

	@Override
	public boolean flush() {

		return true;
	}

	@Override
	public boolean rollback() {

		return true;
	}

}
